#include <stdio.h>
#include <string.h>

#include <util/delay.h>

#include "../nvm.h"
#include "../lcd.h"
#include "../spi.h"
#include "../util.h"

int
main(void)
{
	uint8_t buf[128];
	int i;
	char str[128];

	lcd_init();
	spi_init();
	nvm_unlock();

#if 0
	nvm_erase();
	fatal("done");
#endif

#if 0
	memset(buf, 0, sizeof(buf));
	nvm_read(buf, 0x00000005, sizeof(buf));
	for (i = 0; i < 128; ++i) {
		lcd_clrscr();
		lcd_home(0);
		sprintf(str, "%d: %02X", i, buf[i]);
		lcd_print(str);
		_delay_ms(250);
	}
#else
	for (i = 0; i < 128; ++i)
		buf[i] = i;
	nvm_write(0x00000000, buf, sizeof(buf));

	_delay_ms(1000);
	lcd_clrscr();
	lcd_home(0);
	lcd_print("all done.");
#endif

#if 0
	status = nvm_status(NVM_READ, 0);

	sprintf(str, "0x%02X", status);
	lcd_print(str);
	_delay_ms(500);

	nvm_wel(NVM_SET);
	_delay_ms(500);
		
	lcd_clrscr();
	lcd_home(0);
	nvm_read(&b, 0x00000000, 1);	
	sprintf(str, "0x%02X", b);
	lcd_print(str);
	_delay_ms(1000);
#endif

	fatal("end of program");

	return 0;
}
